import javax.swing.*;
import java.awt.event.*;

public class CanvasEditor implements ActionListener, MouseListener
{
	private JButton selectedButton;

	public CanvasEditor(JButton initialSelectedButton)
	{
		this.selectedButton = initialSelectedButton;
	}

	public void actionPerformed(ActionEvent e)
	{
		selectedButton = (JButton) e.getSource();
	}

	public void mouseClicked(MouseEvent e)
	{
		int x = e.getX();
		int y = e.getY();
		JPanel canvas = (JPanel) e.getSource();

		if(selectedButton.getText().equals("Ellipse"))
			canvas.getGraphics().drawOval(x-30, y-20, 60, 40);
		else if(selectedButton.getText().equals("Rect"))
                        canvas.getGraphics().drawRect(x-30, y-20, 60, 40);
		else if(selectedButton.getText().equals("Square"))
                        canvas.getGraphics().drawRect(x-25, y-25, 50, 50);
	}


	public void mousePressed(MouseEvent e){}
        public void mouseReleased(MouseEvent e){}
        public void mouseEntered(MouseEvent e){}
        public void mouseExited(MouseEvent e){}

}
